package com.bjpowernode.springboot.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.bjpowernode.springboot.domain.Student;
import com.bjpowernode.springboot.mapper.StudentMapper;
import com.bjpowernode.springboot.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;


import java.util.List;

/**
 * CreateTime：2020/9/2 16:53
 */

@Component
@Service(interfaceClass = StudentService.class, version = "1.0.0", timeout = 5000)
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public List<Student> getStudentList() {

        List student = redisTemplate.opsForList().range("student", 0, -1);

        if(student == null || student.size() <= 0) {
            student = studentMapper.selectByExample(null);
            redisTemplate.opsForList().leftPushAll("student",student);
            System.out.println("从数据库中获取数据");
        }else{
            System.out.println("redis中获取数据");
        }
        return student;
    }
}
